﻿Imports System.Data.OleDb
Public Class comment
    Inherits System.Web.UI.Page

    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load

    End Sub

    Protected Sub cmdcomment_Click(ByVal sender As Object, ByVal e As EventArgs) Handles cmdcomment.Click

        Dim oleDbConn As New OleDb.OleDbConnection(ConfigurationManager.ConnectionStrings("ConnectionString").ConnectionString)
        Dim SqlString As String = "Insert into comment(title, comments, category, author) Values (@f1,@f2,@f3, @f4)"
        ' choose dish category
        If lstcategory.SelectedIndex = 0 Then txtcategory.Text = "others"
        If lstcategory.SelectedIndex = 1 Then txtcategory.Text = "swallow"
        If lstcategory.SelectedIndex = 2 Then txtcategory.Text = "soup or stew"
        If lstcategory.SelectedIndex = 2 Then txtcategory.Text = "general"

        Dim cmd As OleDbCommand = New OleDbCommand(SqlString, oleDbConn)
        cmd.CommandType = CommandType.Text
        cmd.Parameters.AddWithValue("@f1", txtitle.Text)
        cmd.Parameters.AddWithValue("@f2", txtcomment.Text)
        cmd.Parameters.AddWithValue("@f3", txtcategory.Text)
        cmd.Parameters.AddWithValue("@f5", User.Identity.Name)

        oleDbConn.Open()
        cmd.ExecuteNonQuery()

        txtitle.Text = ""
        txtcomment.Text = ""
        txtcategory.Text = ""
        Response.Redirect("confirmation.aspx")
    End Sub
End Class